<template>
  <el-form ref="postForm_examine" :model="postForm_examine" :rules="rules">
    <sticky :class-name="'sub-navbar'" v-show="!adminshow">
      <el-button v-if="!isEdit" @click="showGuide">显示帮助</el-button>
      <el-button
        v-loading="loading"
        type="success"
        style="margin-left: 10px"
        @click="submitForm"
      >
        {{ isEdit ? '审核报名表' : '新增报名表' }}
      </el-button>
    </sticky>
    <div class="detail-container">
      <el-row>
        
        <el-col :span="24">    
              <el-form-item prop="examine_status" label="审核状态：" :label-width="labelWidth" v-show="!adminshow">
                <el-select v-model="postForm_examine.examine_status" placeholder="请选择" clearable>
                   <el-option
                      v-for="item in examine_options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item> 
              <el-form-item prop="examine_explain" label="审核说明：" :label-width="labelWidth" v-show="!adminshow">
                <el-input
                  type="textarea"
                  :rows="3"
                  placeholder="请输入审核说明"
                  v-model="postForm_examine.examine_explain">
                >
                </el-input>
              </el-form-item>  
                 
              <div>
               姓名： {{this.postForm.enroll_name}}
              </div> 
                      
              <el-form-item prop="post" label="报考岗位：" :label-width="labelWidth">
                {{this.postForm.post}}
              </el-form-item>  
              <el-form-item prop="post_code" label="岗位代码：" :label-width="labelWidth" >
                {{this.postForm.post_code}}
              </el-form-item>
              <el-form-item prop="date_of_birth" label="出生年月：" :label-width="labelWidth" >
                {{this.postForm.date_of_birth}}
              </el-form-item>
              <el-form-item prop="sex" label="性别："  :label-width="labelWidth" >
                {{this.postForm.sex}}
              </el-form-item>
              <el-form-item prop="ethnic" label="民族：" :label-width="labelWidth">
                {{this.postForm.ethnic}}
              </el-form-item>
              <el-form-item prop="politics_status_time" label="政治面貌及加入时间：" :label-width="labelWidth" >
                {{this.postForm.politics_status_time}}
              </el-form-item>
              <el-form-item prop="education_background" label="学历：" :label-width="labelWidth" >
                {{this.postForm.education_background}}
              </el-form-item>
              <el-form-item prop="degree" label="学位：" :label-width="labelWidth" >
                {{this.postForm.degree}}
              </el-form-item>
              <el-form-item prop="school_and_date_of_graduation" label="毕业学校：" :label-width="labelWidth" >
                {{this.postForm.school_and_date_of_graduation}}
              </el-form-item>
              <el-form-item prop="graduation_time" label="毕业时间：" :label-width="labelWidth" >
                {{this.postForm.graduation_time}}
              </el-form-item>
              <el-form-item prop="what_specific" label="所学专业：" :label-width="labelWidth" >
                {{this.postForm.what_specific}}
              </el-form-item>
              <el-form-item prop="main_specialties" label="主要特长：" :label-width="labelWidth" >
                {{this.postForm.main_specialties}}
              </el-form-item>
              <el-form-item prop="Current_Registered_Household" label="现户口所在地：" :label-width="labelWidth" >
                {{this.postForm.Current_Registered_Household}}
              </el-form-item>
              <el-form-item prop="ID_card_No" label="身份证号码：" :label-width="labelWidth" >
                {{this.postForm.ID_card_No}}
              </el-form-item>
              <el-form-item prop="contact_way" label="联系方式：" :label-width="labelWidth" >
                {{this.postForm.contact_way}}
              </el-form-item>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="achievement" label="现在研究方向及主要成果：" :label-width="labelWidth">
                {{this.postForm.achievement}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="resume" label="本人主要简历：" :label-width="labelWidth">
                {{this.postForm.resume}}
              </el-form-item>
            </el-col>
          </el-row>         
          <el-row>
            <el-col :span="24">
              <el-form-item prop="enroll_img" label="上传的证明材料：" :label-width="labelWidth">
                <el-row :span="16" v-for="(o, index) in fileList">
                <el-card :body-style="{ padding: '0px' }">
                  <img :src="o.url" class="image">
                  <div style="padding: 14px;">
                    <span>{{o.name}}</span>
                  </div>
                </el-card>
                </el-row>
              </el-form-item>
            </el-col> 
          </el-row>
        </el-col>
      </el-row>
      
    </div>
  </el-form>
</template>

<script>
// eslint-disable-next-line
/* eslint-disable */
import Cookies from 'js-cookie'
import { mapGetters } from 'vuex'
import Sticky from '../../../components/Sticky'
import Warning from './Warning'
import { createEnroll, updateEnroll, getOneEnroll ,listEnroll ,createEnrollExamine } from '../../../api/enroll'
import MarkdownEditor from '@/components/MarkdownEditor'
const fields = {
  
}
export default {
  components: { Sticky, Warning, MarkdownEditor },
  props: {
    isEdit: Boolean
  },
  data() {
    const validateRequire = (rule, value, callback) => {
      if (value.length === 0) {
        callback(new Error(fields[rule.field] + '必须填写'))
      } else {
        callback()
      }
    }
    return {
      loading: false,
      postForm_examine: {examine_status:'', examine_name:'',examine_operator:'',examine_time:''},
      postForm:{},
      fileList: [],
      fileList_enroll:[],
      listQuery: {},
      arr:[],
      userInfo: {},
      labelWidth: '120px',
      categoryList:[],
      date_of_birth:'',
      baoming:'',
      adminshow:false,
      listbaoming:[],
      rules: {
        examine_explain: [{ required: true, message: '请输入审核说明', trigger: 'blur' }],
        examine_status: [{required: true, message: '请选择审核状态', trigger: 'change'}],
      },
      examine_options:[
        {
          value: '未提交',
          label: '未提交'
        }, 
        {
          value: '初审通过',
          label: '初审通过'
        }, {
          value: '终审通过',
          label: '终审通过'
        }]
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
        if (this.isEdit) {
          //判断是否是admin用户
          let usernameinfo=Cookies.get('username')
          if(usernameinfo!='admin'){
              this.adminshow=true
            }
          const fileName = this.$route.params.fileName
          getOneEnroll(fileName).then(response => {
            console.log(response)
            this.postForm=response.data
            this.postForm_examine.examine_status=response.data.enroll_status
            this.arr = JSON.parse(response.data.enroll_img)
            //console.log(this.arr1)
        this.arr.forEach((item)=>{
          //console.log(item.name)
            this.fileList.push({name: item.name, url: item.url})
            //console.log(this.fileList)
        })

      }
   ).catch(() => {
        this.loading = false
      })
      console.log(fileName)
    }
    //this.getCategoryList()
      
      //}
  },
  methods: {
    onContentClick(data) {
      //console.log(data)
      if (data.text) {
        window.open(data.text)
      }
    },
    setDefault() {
      // this.postForm = Object.assign({}, defaultForm)
      this.$router.push({
        path: '/enroll/list',
      })
      //this.postForm={state:"1"}
    },
    
    onsuccess(res){
       this.$notify({
          title: '上传资料图片成功',
          message: '上传资料图片成功',
          type: 'success',
          duration: 2000
        })     
    },
    submitForm() {
      const onSuccess = (response) => {
        const { msg } = response
        this.$notify({
          title: '操作成功',
          message: msg,
          type: 'success',
          duration: 2000
        })
        this.loading = false
      }

      if (!this.loading) {
        this.loading = true
        //this.postForm.enroll_status="已提交"
        
        this.$refs.postForm_examine.validate((valid, fields) => {
          console.log(valid, fields)
          if (valid) {
            let usernameinfo=Cookies.get('username')
            this.postForm.enroll_status=this.postForm_examine.examine_status
            this.postForm_examine.examine_operator=usernameinfo
            this.postForm_examine.examine_name=this.postForm.enroll_adminuser
            const enroll = Object.assign({}, this.postForm)
            const enroll_examine=Object.assign({}, this.postForm_examine)
            //console.log(enroll)
            
              updateEnroll(enroll).then(response => {
                onSuccess(response)
                createEnrollExamine(enroll_examine).then(responsel => {
                  onSuccess(responsel)
                  this.setDefault()
                }).catch(() => {
                  this.loading = false
                })
              }).catch(() => {
                this.loading = false
              })
            
          } else {
            const message = fields[Object.keys(fields)[0]][0].message
            this.$message({ message, type: 'error' })
            this.loading = false
          }
        })
      }
    },
    showGuide() {
      console.log('show guide...')
    }
  }
}
</script>

<style lang="scss" scoped>
  .detail-container {
    padding: 40px 50px 20px;
    .preview-img {
      width: 200px;
      height: 270px;
    }
  }
  .image {
    width: 600px;
    height:400px;
    display: block;
  }
</style>
